package com.hejiale.lease.common.minio;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description: minio配置类,提供MinioClient
 * @author: HeJiale
 * @since 2025/3/14 下午7:21
 */
@ConditionalOnProperty(name = "minio.endpoint") // 判断是否配置了minio的endpoint，如果没有则不加载该类
@Configuration
public class MinioConfiguration {

    private final MinioProperties properties;

    @Autowired
    public MinioConfiguration(MinioProperties properties) {
        this.properties = properties;
    }

    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder()
                .endpoint(properties.getEndpoint())
                .credentials(properties.getAccessKey(), properties.getSecretKey())
                .build();
    }
}
